package com.personal.gateway.flinkAllCommand;

import com.alibaba.fastjson.JSONObject;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOption;
import com.personal.gateway.flinkAllCommand.configurationOption.ConfigurationOptionBuilder;
import com.personal.gateway.flinkAllCommand.configurationOption.KeyIndexInfomationDao;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationGenerator.ConfigurationGeneratorString;
import com.personal.gateway.flinkAllCommand.configurationOption.configurationType.*;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.parameterCheck.ParameterCheckString;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorEnum;
import com.personal.gateway.flinkAllCommand.configurationOption.webObjectGenerator.WebObjectGeneratorString;

import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkExecutionEnum.EXECUTION_TYPE_CLASS;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkFileSystemEnum.FILE_SYSTEM_ENUM_TYPE_CLASS;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkMetricsEnum.FLINK_METRICS_ENUM_TYPE_CLASS;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkTargetEnum.TARGET_TYPE_CLASS;
import static com.personal.gateway.custom.customEnum.flinkCommandEnum.FlinkVersionEnum.FLINK_VERSION_TYPE_CLASS;
import static com.personal.gateway.flinkAllCommand.FlinkMemory.FLINK_MEMORY_TYPE_CLASS;
import static com.personal.gateway.flinkAllCommand.flinkEnvironment.FlinkEnvironmentTypeClass.FLINK_ENVIRONMENT_TYPE_CLASS;
import static com.personal.gateway.flinkAllCommand.flinkFileSystem.FlinkFileSystemTypeClass.FLINK_FILE_SYSTEM_TYPE_CLASS;
import static com.personal.gateway.flinkAllCommand.flinkMetrics.FlinkMetricsTypeClass.FLINK_METRICS_TYPE_CLASS;

/**
 * @author BigHead
 * @date 2022/1/20 14:02
 * @description FlinkExecuteCommand
 */
public class FlinkExecuteCommand extends AbstractConfigurationTypeClass {

    private static final KeyIndexInfomationDao BASE_CONFIG = new KeyIndexInfomationDao("基础配置", 1);
    public static final KeyIndexInfomationDao MEMORY_CONFIG = new KeyIndexInfomationDao("内存配置", 2);
    public static final KeyIndexInfomationDao ENVIRONMENT_CONFIG = new KeyIndexInfomationDao("执行环境", 3);

    public static final KeyIndexInfomationDao FILE_SYSTEM_CONFIG = new KeyIndexInfomationDao("文件系统", 6);
    public static final KeyIndexInfomationDao METRICS_CONFIG = new KeyIndexInfomationDao("监控配置", 7);


    private final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> flinkVersion = ConfigurationOptionBuilder
            .startBuilder(BASE_CONFIG, new KeyIndexInfomationDao("FLINK_VERSION", 1))
            .webShowName("Flink版本")
            .describe("选择使用版本")
            .typeEnum(FLINK_VERSION_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> executeEnum = ConfigurationOptionBuilder
            .startBuilder(BASE_CONFIG, new KeyIndexInfomationDao("EXECUTE_TYPE", 2))
            .webShowName("flink执行方式")
            .describe("执行方式")
            .typeEnum(EXECUTION_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> targetEnum = ConfigurationOptionBuilder
            .startBuilder(BASE_CONFIG, new KeyIndexInfomationDao("TARGET", 3))
            .webShowName("启动方式")
            .describe("启动方式")
            .antecedentConfigurationOption(executeEnum)
            .typeEnum(TARGET_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<String, ConfigurationTypeString> startClass = ConfigurationOptionBuilder
            .startBuilder(BASE_CONFIG, new KeyIndexInfomationDao("START_CLASS", 4))
            .webShowName("项目启动类")
            .describe("Jar包中选择启动的类全路径")
            .typeString()
            .setExampleValue("xxx.xxx.xxx.StartMain")
            .webObjectGenerator(WebObjectGeneratorString.class)
            .parameterCheck(ParameterCheckString.class)
            .configurationGenerator(ConfigurationGeneratorString.class)
            .build();

    public final ConfigurationOption<AbstractConfigurationTypeClass, ConfigurationTypeClass> memory = ConfigurationOptionBuilder
            .startBuilder(MEMORY_CONFIG, new KeyIndexInfomationDao("", 5))
            .typeClass(FLINK_MEMORY_TYPE_CLASS)
            .webObjectGenerator(null)
            .parameterCheck(null)
            .configurationGenerator(null)
            .build();

    public final ConfigurationOption<AbstractConfigurationTypeClass, ConfigurationTypeClass> startEnv = ConfigurationOptionBuilder
            .startBuilder(ENVIRONMENT_CONFIG, new KeyIndexInfomationDao("", 6))
            .antecedentConfigurationOption(targetEnum)
            .typeClass(FLINK_ENVIRONMENT_TYPE_CLASS)
            .webObjectGenerator(null)
            .parameterCheck(null)
            .configurationGenerator(null)
            .build();


    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> FILE_SYSTEM = ConfigurationOptionBuilder
            .startBuilder(FILE_SYSTEM_CONFIG, new KeyIndexInfomationDao("FILE_SYSTEM", 1))
            .webShowName("文件系统")
            .describe("选择指定的文件系统")
            .typeEnum(FILE_SYSTEM_ENUM_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<AbstractConfigurationTypeClass, ConfigurationTypeClass> FILE_SYSTEM_CLASS = ConfigurationOptionBuilder
            .startBuilder(FILE_SYSTEM_CONFIG, new KeyIndexInfomationDao("FILE_SYSTEM_CLASS", 8))
            .antecedentConfigurationOption(FILE_SYSTEM)
            .typeClass(FLINK_FILE_SYSTEM_TYPE_CLASS)
            .webObjectGenerator(null)
            .parameterCheck(null)
            .configurationGenerator(null)
            .build();

    public final ConfigurationOption<Enum<? extends ConfigurationTypeEnumInterface>, ConfigurationTypeEnum> METRICS_SYSTEM = ConfigurationOptionBuilder
            .startBuilder(METRICS_CONFIG, new KeyIndexInfomationDao("METRICS_SYSTEM", 1))
            .webShowName("外部监控系统")
            .describe("选择指定外部监控系统")
            .typeEnum(FLINK_METRICS_ENUM_TYPE_CLASS)
            .webObjectGenerator(WebObjectGeneratorEnum.class)
            .parameterCheck(ParameterCheckEnum.class)
            .configurationGenerator(ConfigurationGeneratorEnum.class)
            .build();

    public final ConfigurationOption<AbstractConfigurationTypeClass, ConfigurationTypeClass> METRICS_SYSTEM_CLASS = ConfigurationOptionBuilder
            .startBuilder(METRICS_CONFIG, new KeyIndexInfomationDao("METRICS_SYSTEM_CLASS", 8))
            .antecedentConfigurationOption(METRICS_SYSTEM)
            .typeClass(FLINK_METRICS_TYPE_CLASS)
            .webObjectGenerator(null)
            .parameterCheck(null)
            .configurationGenerator(null)
            .build();

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        JSONObject webJson = new JSONObject();

        FlinkExecuteCommand flinkExecuteCommand = new FlinkExecuteCommand();

//        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

        webJson.put("EXECUTE_TYPE", "run");
//        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

        webJson.put("TARGET", "kubernetes-session");
        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
//        webJson.put("kubernetes000container000image", "yarn-session-test");
//        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
//
//
//        webJson.put("target", "kubernetes-session");
//        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
//        webJson.put("kubernetes000jobmanager000owner000reference", "p:p,o:o,i:i");
//        System.out.println(flinkExecuteCommand.getWebElement(webJson));
//        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");


    }

}
